package br.com.projeto.dao.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.projeto.sakila.bean.Actor;

public class ActorDao {
	
	public long buscarActor(Connection connection){
		long tempoInicial = System.currentTimeMillis();
		
		try {
			PreparedStatement preparedStatement = 
					connection.prepareStatement("select actor_id, first_name, last_name, last_update from actor");
			
			ResultSet resultSet = preparedStatement.executeQuery();
			List<Actor> listActor = new ArrayList<>();
			Actor actor;
			while(resultSet.next()){
				actor = null;
				actor = new Actor();
				actor.setId(Integer.parseInt(resultSet.getString("actor_id")));
				actor.setFirstName(resultSet.getString("first_name"));
				actor.setLastName(resultSet.getString("last_name"));
				actor.setLastUpdate(resultSet.getDate("last_update"));
				
				listActor.add(actor);
			}
			
			resultSet.close();
			preparedStatement.close();
			
		} catch (SQLException exception) {
			System.err.println("Erro JDBC" + exception);
			throw new RuntimeException(exception);
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}

}
